package com.tqjc.system.core.redis;

import org.quartz.spi.TriggerFiredBundle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.scheduling.quartz.AdaptableJobFactory;
import org.springframework.stereotype.Component;

/**
 * @Description: TODO
 * @author: pzy
 * @date: 2022年05月15日 17:19
 */
@Component("redisApiFactory")
public class RedisApiFactory extends AdaptableJobFactory {
    @Autowired
    private AutowireCapableBeanFactory autowireCapableBeanFactory;

    /**
     * 该方法需要将实例化的任务对象手动的添加到spring IOC容器中，并且完成该对象注入
     * */
    @Override
    protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception{
        Object obj = super.createJobInstance(bundle);
        //将obj对象添加spring IOC容器中，并完成注入
        autowireCapableBeanFactory.autowireBean(obj);
//        this.autowireCapableBeanFactory.autowireBean(obj);
        return obj;
    }
}
